import os
from openai import OpenAI
from Initializer import Initializer

class Embedding:
    def __init__(self):
        # 初始化 APIKEY 和 BASEURL
        Initializer.init()

        self.client = OpenAI(
            api_key=os.environ.get("APIKEY"),
            base_url=os.environ.get("BASEURL"),
        )
    
    def embedding(self, text: str) -> list[float]:
        resp = self.client.embeddings.create(
            model=os.environ.get("EMBEDDINGMODELID"),
            input=[text],
            encoding_format="float"
        )
        return resp.data[0].embedding